﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Linq;
using System.Text;

namespace Learn.Service.Interface
{
    /// <summary>
    /// 基础EF实现类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface I_Base_EFCore<T> where T : class,new()
    {
        T Find(params object[] keys);

        void Add(T t);

        void AddRange(IEnumerable<T> ie);

        void Update(T t);

        void UpdateRange(IEnumerable<T> ie);

        void Delete(T t);

        void DeleteRange(IEnumerable<T> ie);

        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        int SaveChanges();

        IQueryable<T> QueryAll(Expression<Func<T, bool>> where = null);

        IQueryable<T> QueryAll<type>(bool isAsc, Expression<Func<T, type>> order, Expression<Func<T, bool>> where = null);

        IQueryable<T> QueryAll<type>(out int total, int skip, int limit, bool isAsc, Expression<Func<T, type>> order, Expression<Func<T, bool>> where = null);

        /// <summary>
        /// 分布式事务操作
        /// 
        /// 同时处理两个对象
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="tran1"></param>
        /// <returns></returns>
        bool Transactions<T1>(I_Base_EFCore<T1> tran1)
            where T1 : class, new();

        /// <summary>
        /// 分布式事务操作
        /// 
        /// 同时处理三个对象
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="tran1"></param>
        /// <param name="tran2"></param>
        /// <returns></returns>
        bool Transactions<T1, T2>(I_Base_EFCore<T1> tran1, I_Base_EFCore<T1> tran2)
            where T1 : class, new()
            where T2 : class, new();

    }
}
